package bdclass;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.util.Properties;

public class Conexion {
    
    private Connection con;
    private Statement st;
    
    
    public Connection getCon() {
        return con;
    }


    public Statement getSt() {
        return st;
    }

    public void setSt(Statement st) {
        this.st = st;
    }



    public Statement connect() //regresa un objeto statement
    {
        con =null;
        st=null;
        Leer l=new Leer();
        Propiedades p=new Propiedades();
        try
         {
             p=l.Leer_doc();
             
             Properties prop=new Properties();
             prop.setProperty("user", p.getUsuario());
             prop.setProperty("password", p.getPassword());
             con=DriverManager.getConnection(p.getDireccion(),prop);
             st=con.createStatement();
             
         }catch(Exception ex)
         {

         }
        return st;
    }

       public PreparedStatement connect(String sql) //regresa un objeto statement
    {
        con =null;
        st=null;
        PreparedStatement ps=null;
        
        Leer l=new Leer();
        Propiedades p=new Propiedades();
        
        try
         {
             p=l.Leer_doc();
             Properties prop=new Properties();
             
             prop.setProperty("user", p.getUsuario());
             prop.setProperty("password", p.getPassword());
             con=DriverManager.getConnection(p.getDireccion(),prop);         
             st=con.createStatement();
             ps=con.prepareStatement(sql);
         }catch(Exception ex)
         {

         }
        return ps;
    }

}
